# coding=utf-8

import scrapy

"""
    登录策略二: 标准的模拟登录步骤
"""

class Renren2Spider(scrapy.Spider):
    name = "renren2"
    allow_domains = ["renren.com"]
    start_urls = [
        "http://www.renren.com/PLogin.do"
    ]

    def parse(self, response):
        # 提取登录需要的参数
        # _xsrf = response.xpath("//_xsrf").extract()[0]

        # 发送请求参数,并调用指定回调函数处理
        yield scrapy.FormRequest.from_response(
            response,
            formdata={
                "email": "17612153143",
                "password": "fyy...354109"
            },
            callback=self.parse_page
        )

    def parse_page(self, response):
        # 个人中心
        url = "http://www.renren.com/967677932/profile"
        yield scrapy.Request(url=url, callback=self.parse_newpage)


    def parse_newpage(self, response):
        with open("fyy.html", "w") as file:
            file.write(response.body)